import java.io.IOException;

import javax.swing.JOptionPane;


/**
 * Call unix terminal
 * 
 * @author root
 * 
 */
public class Nnet {

	public Nnet(int width, int height, int file, Main main, int blocchiX) {
		try {
			Process cat = Runtime.getRuntime().exec("jar xf MyAsciiArt_v1.1.jar nnet train.txt");
			// Process cat = Runtime.getRuntime().exec("jar xf MyAsciiArt_v1.2.jar nnet train.txt");
			cat.waitFor();
			cat = Runtime.getRuntime().exec("chmod +x nnet");
			cat.waitFor();

			// creo file per ogni blocco e lo analizzo , cambio nome al log#
			for (int i = 1; i <= file; i++) {
				try {
					cat = Runtime.getRuntime().exec("./nnet train.txt myTest" + i + ".txt -hl 1 16");
					cat.waitFor();
					cat = Runtime.getRuntime().exec("mv log.txt log" + i + ".txt");
					cat.waitFor();
					cat = Runtime.getRuntime().exec("rm myTest" + i + ".txt");
					cat.waitFor();
				} catch (InterruptedException e) {
					JOptionPane.showMessageDialog(null, "Errore esecuzione NNET");
					e.printStackTrace();
				}

			}
			cat = Runtime.getRuntime().exec("rm nnet train.txt");

			new Reader(main, file, blocchiX);

		} catch (IOException e) {
			JOptionPane.showMessageDialog(null, "Errore esecuzione NNET");
			e.printStackTrace();
		} catch (InterruptedException e) {
			JOptionPane.showMessageDialog(null, "Errore attesa NNET");
			e.printStackTrace();
		}
	}
}
